package com.turtle3d.util;

/**
 * Helper class for finding minimal and maximal value.
 * 
 * @author Marek Paterczyk <marek.paterczyk@gmail.com>
 *
 */
public class ExtremalValue {
	
	private float maximum=0;
	private float minimum=0;		
	
	public ExtremalValue(float value) {
		super();
		maximum=minimum=value;		
	}
	public ExtremalValue(){
		
	}
	
	public ExtremalValue(ExtremalValue extremalValue){
		maximum=extremalValue.maximum;
		minimum=extremalValue.minimum;
	}
		
	/**
	 * Sets value only if it's the new extremum. 
	 * @param value
	 * @return
	 */
	public boolean setValue(float value){
		if(value>this.maximum){
			this.maximum=value;
			return true;
		}
		if(value<this.minimum){
			this.minimum=value;
			return true;
		}
		return false;
	}
	
	public float getMaximumValue() {
		return maximum;
	}
	
	public float getMinimumValue() {
		return minimum;
	}
	
	public float getMiddleValue(){
		return minimum+(maximum-minimum)/2f;		
	}
	
	public float getDifferenceValue(){
		return maximum-minimum;
	}
	
	public String toString(){
		return "Max: "+maximum+", Min: "+minimum;
	}

}
